package com.wenli.graduate2022.wenliGreenShop.service.servImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wenli.graduate2022.wenliGreenShop.entity.Product;
import com.wenli.graduate2022.wenliGreenShop.repository.mapper.ProductMapper;
import com.wenli.graduate2022.wenliGreenShop.service.servDao.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author HuangHai
 * @date 2021/10/6 16:05
 */
@Service
public class ProductServImpl implements ProductService {

    @Autowired
    ProductMapper productMapper;

    @Override

    public List<Product> findAll() {
        return productMapper.findAll();
    }

    /**
     * 查询某个页面的数据
     * @param page
     * @return
     */
    @Override
    public IPage<Product> findByPage(Page page) {
        return productMapper.findByPage(page);
    }

    @Override
    public Product findById(Integer id) {
        return productMapper.findById(id);
    }

    /**
     * 插入
     * @param product
     * @return
     */
    @Override
    public int insert(Product product) {
        return productMapper.insert(product);
    }

    @Override //修改
    public int update(Product product) {
        return productMapper.update(product);
    }

    @Override  //删除
    public int delete(Integer id) {
        return productMapper.delete(id);
    }

    @Override  //模糊查询
    public IPage<Product> findByName(Page page,String name) {
        return productMapper.findByName(page,name);
    }

    @Override
    public int selectLastInsertId() {  //返回最后插入的mysql自动生成的id
        return productMapper.selectLastInsertId();
    }

    @Override
    public List<Product> findProductsByCategory(String category) {
        return null;
    }

    @Override
    public List<Product> findProductsByCategoryId(Integer id) {
        return productMapper.findByCategoryId(id);
    }
}
